﻿using System;
using System.Collections.Generic;
using System.Linq;
using Common.Constants;
using Common.Helper;
using Common.Interface;

namespace MainProcessor.Processors
{
    public class ReportingFilterProcessor : BaseElementProcessor, IReportingFilter
    {
        public bool UseFundNameInReport
        {
            get
            {
                return GetValue<string>(ReportingFilterName.FundName.ToDescription(), XmlConstants.FilterType) != default(string);
            }
        }

        private static readonly IEnumerable<string> Disclosures = Enum.GetValues(typeof(MacDisclosureName)).Cast<MacDisclosureName>().Select(x => x.ToDescription());

        public DateTime DisclosureAsOfDate
        {
            get
            {
                var disclosureAsOfDate = Disclosures.Max(x => GetValue<DateTime>(x, XmlConstants.EffvFromDt));
                if (disclosureAsOfDate == default(DateTime))
                    disclosureAsOfDate = DateTime.Today;
                return disclosureAsOfDate;

            }
        }


        public short MacPositionLevelData
        {
            get { return GetValue<string>(MacDisclosureName.MacPositionLevelData.ToDescription(), XmlConstants.FilterType) == default(string) ? MacPositionLevelDataWhenAggregated : (short)1; }
        }

        public short MacPositionLevelDataWhenAggregated
        {
            get { return GetValue<string>(MacDisclosureName.MacPositionLevelDataWhenAggregated.ToDescription(), XmlConstants.FilterType) == default(string) ? (short)0 : (short)2; }
        }

        public short MacPortfolioRiskData
        {
            get
            {
                return GetValue<string>(MacDisclosureName.MacPortfolioRiskData.ToDescription(), XmlConstants.FilterType) == default(string) ? MacPortfolioRiskDataWhenAggregated : (short)1; 
            }
        }

        public short MacPortfolioRiskDataWhenAggregated
        {
            get { return GetValue<string>(MacDisclosureName.MacPortfolioRiskDataWhenAggregated.ToDescription(), XmlConstants.FilterType) == default(string) ? (short)0 : (short)2; }
        }

        public short MacData
        {
            get { return GetValue<string>(MacDisclosureName.MacData.ToDescription(), XmlConstants.FilterType) == default(string) ? (short)0 : (short)1; }
        }

        public short MacOtherReferenceFundData
        {
            get { return GetValue<string>(MacDisclosureName.MacOtherReferenceFundData.ToDescription(), XmlConstants.FilterType) == default(string) ? (short)0 : (short)1; }
        }

        public short ReportingData_3
        {
            get { return GetValue<string>(MacDisclosureName.ReportingData_3.ToDescription(), XmlConstants.FilterType) == default(string) ? (short)0 : (short)1; }
        }

        public bool MacShowReferenceFundNameinMacReporting
        {
            get { return GetValue<string>(MacDisclosureName.MacShowReferenceFundNameinMacReporting.ToDescription(), XmlConstants.FilterType) != default(string); }
        }

        public bool UseReferenceFundInReporting
        {
            get { return GetValue<string>(MacDisclosureName.UseReferenceFundInReporting.ToDescription(), XmlConstants.FilterType) != default(string); }
        }
    }
}
